﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using hiednsLib;

namespace BrsdServer
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class find2 : IHttpHandler
    {
        string mac = find1.mac;
        string ip = find1.ip;
        hiednsLib.DnsModifyClass hiedns = new hiednsLib.DnsModifyClass();
        dnsInfoBLL dnsinfo = new dnsInfoBLL();
        userInfoBLL userInfo = new userInfoBLL();

        public void ProcessRequest(HttpContext context)
        {
            //////////////////////////////////////////////////////////////////////////
            //有三种返回值。绑定失败-1 绑定成功 0 
            // 如果域名已存在则返回2
            //////////////////////////////////////////////////////////////////////////
            int user_id=userInfo.GetUserID(find.username, find.userpwd);
            context.Response.ContentType = "text/plain";
            string txtBind = context.Request.QueryString["txtBind"];
            int bindflag = dnsinfo.BindMac(txtBind);
            if (bindflag==0)
            {
                string server_domain = System.Configuration.ConfigurationManager.AppSettings["domain"];
                string server_ip = System.Configuration.ConfigurationManager.AppSettings["ip"];
                hiedns.SetDnsSvr(server_domain, server_ip, 0);
                int ret = hiedns.Hie_DnsModify(mac, txtBind, ip, 0);
                int x = dnsinfo.Update(mac, user_id, txtBind);
                context.Response.Write(ret);
            } 
            else
            {
                context.Response.Write(2);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
